/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/07/12
* File: SceneManager.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "SceneNode.h"
#include "../RenderSystem/LightData.h"
#include "../RenderSystem/RenderSystem.h"
#include "../RenderSystem/Texture.h"
#include "../RenderSystem/LightData.h"
#include "../RenderSystem/MaterialData.h"
#include "SceneManager.h"

SceneManager::SceneManager(RenderSystem* render_system)
: _render_system(render_system)
{

}

SceneManager::~SceneManager()
{
	
}

void SceneManager::clipScene()
{

}

void SceneManager::addSceneNode(SceneNode* scene_node)
{
	_scene_node_list.push_back(scene_node);
}

void SceneManager::addSkyboxSceneNode(SkyboxSceneNode* skybox)
{
	_skybox_scene_node_list.push_back(skybox);
}

void SceneManager::addLightSceneNode(LightSceneNode* light_node)
{
	_light_scene_node_list.push_back(light_node);
}

void SceneManager::setActiveCamera(CameraSceneNode* camera_node)
{
	_active_camera_scene_node = camera_node;
}

CameraSceneNode* SceneManager::getActiveCameraNode() const
{
	return _active_camera_scene_node;
}

RenderSystem* SceneManager::getRenderSystem() const
{
	return _render_system;
}

void SceneManager::render()
{
	/* 1.render camera */
	/* must have camera, if not, just crash! */
	_active_camera_scene_node->render();

	/* 2.render light */
	_render_system->deleteAllLights();
	LightSceneNodeList::iterator light_iter = _light_scene_node_list.begin();
	for(; light_iter != _light_scene_node_list.end(); ++light_iter)
	{
		(*light_iter)->render();
	}

	/* 3.render skybox */
	SkyboxSceneNodeList::iterator skybox_iter = _skybox_scene_node_list.begin();
	for(; skybox_iter != _skybox_scene_node_list.end(); ++skybox_iter)
	{
		(*skybox_iter)->render();
	}

	/* 4.render default objects */
	SceneNodeList::iterator iter = _scene_node_list.begin();
	for(; iter != _scene_node_list.end(); ++iter)
	{
		(*iter)->render();
	}
}



